namespace BudgetApp.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class initial : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        CategoryId = c.Int(nullable: false, identity: true),
                        CategoryType = c.String(),
                    })
                .PrimaryKey(t => t.CategoryId);
            
            CreateTable(
                "dbo.CatTypes",
                c => new
                    {
                        CatTypeId = c.Int(nullable: false, identity: true),
                        CategoryId = c.Int(nullable: false),
                        SubCategoryId = c.Int(nullable: false),
                        TypeId = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.CatTypeId)
                .ForeignKey("dbo.Categories", t => t.CategoryId, cascadeDelete: true)
                .ForeignKey("dbo.InputTypes", t => t.TypeId, cascadeDelete: true)
                .ForeignKey("dbo.SubCategories", t => t.SubCategoryId, cascadeDelete: true)
                .Index(t => t.CategoryId)
                .Index(t => t.SubCategoryId)
                .Index(t => t.TypeId);
            
            CreateTable(
                "dbo.InputTypes",
                c => new
                    {
                        TypeId = c.Int(nullable: false, identity: true),
                        Type = c.String(),
                    })
                .PrimaryKey(t => t.TypeId);
            
            CreateTable(
                "dbo.SubCategories",
                c => new
                    {
                        SubCategoryId = c.Int(nullable: false, identity: true),
                        SubCategoryType = c.String(),
                    })
                .PrimaryKey(t => t.SubCategoryId);
            
            CreateTable(
                "dbo.AspNetRoles",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        Name = c.String(nullable: false, maxLength: 256),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.Name, unique: true, name: "RoleNameIndex");
            
            CreateTable(
                "dbo.AspNetUserRoles",
                c => new
                    {
                        UserId = c.String(nullable: false, maxLength: 128),
                        RoleId = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.UserId, t.RoleId })
                .ForeignKey("dbo.AspNetRoles", t => t.RoleId, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);
            
            CreateTable(
                "dbo.TrackBills",
                c => new
                    {
                        BillId = c.Int(nullable: false, identity: true),
                        DateDue = c.DateTime(nullable: false),
                        Amount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Description = c.String(),
                        CategoryType = c.Int(nullable: false),
                        SubCategoryType = c.Int(nullable: false),
                        Type = c.Int(nullable: false),
                        UserId = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.BillId)
                .ForeignKey("dbo.Categories", t => t.CategoryType, cascadeDelete: true)
                .ForeignKey("dbo.InputTypes", t => t.Type, cascadeDelete: true)
                .ForeignKey("dbo.SubCategories", t => t.SubCategoryType, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.UserId)
                .Index(t => t.CategoryType)
                .Index(t => t.SubCategoryType)
                .Index(t => t.Type)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.AspNetUsers",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        FirstName = c.String(nullable: false),
                        LastName = c.String(nullable: false),
                        Email = c.String(maxLength: 256),
                        EmailConfirmed = c.Boolean(nullable: false),
                        PasswordHash = c.String(),
                        SecurityStamp = c.String(),
                        PhoneNumber = c.String(),
                        PhoneNumberConfirmed = c.Boolean(nullable: false),
                        TwoFactorEnabled = c.Boolean(nullable: false),
                        LockoutEndDateUtc = c.DateTime(),
                        LockoutEnabled = c.Boolean(nullable: false),
                        AccessFailedCount = c.Int(nullable: false),
                        UserName = c.String(nullable: false, maxLength: 256),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.UserName, unique: true, name: "UserNameIndex");
            
            CreateTable(
                "dbo.AspNetUserClaims",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserId = c.String(nullable: false, maxLength: 128),
                        ClaimType = c.String(),
                        ClaimValue = c.String(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.AspNetUserLogins",
                c => new
                    {
                        LoginProvider = c.String(nullable: false, maxLength: 128),
                        ProviderKey = c.String(nullable: false, maxLength: 128),
                        UserId = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId })
                .ForeignKey("dbo.AspNetUsers", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.TrackSpends",
                c => new
                    {
                        SpendId = c.Int(nullable: false, identity: true),
                        DateSpent = c.DateTime(nullable: false),
                        Amount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Where = c.String(),
                        Notes = c.String(),
                        CategoryType = c.Int(nullable: false),
                        SubCategoryType = c.Int(nullable: false),
                        Type = c.Int(nullable: false),
                        UserId = c.String(maxLength: 128),
                    })
                .PrimaryKey(t => t.SpendId)
                .ForeignKey("dbo.Categories", t => t.CategoryType, cascadeDelete: true)
                .ForeignKey("dbo.InputTypes", t => t.Type, cascadeDelete: true)
                .ForeignKey("dbo.SubCategories", t => t.SubCategoryType, cascadeDelete: true)
                .ForeignKey("dbo.AspNetUsers", t => t.UserId)
                .Index(t => t.CategoryType)
                .Index(t => t.SubCategoryType)
                .Index(t => t.Type)
                .Index(t => t.UserId);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.TrackSpends", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.TrackSpends", "SubCategoryType", "dbo.SubCategories");
            DropForeignKey("dbo.TrackSpends", "Type", "dbo.InputTypes");
            DropForeignKey("dbo.TrackSpends", "CategoryType", "dbo.Categories");
            DropForeignKey("dbo.TrackBills", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserRoles", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserLogins", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.AspNetUserClaims", "UserId", "dbo.AspNetUsers");
            DropForeignKey("dbo.TrackBills", "SubCategoryType", "dbo.SubCategories");
            DropForeignKey("dbo.TrackBills", "Type", "dbo.InputTypes");
            DropForeignKey("dbo.TrackBills", "CategoryType", "dbo.Categories");
            DropForeignKey("dbo.AspNetUserRoles", "RoleId", "dbo.AspNetRoles");
            DropForeignKey("dbo.CatTypes", "SubCategoryId", "dbo.SubCategories");
            DropForeignKey("dbo.CatTypes", "TypeId", "dbo.InputTypes");
            DropForeignKey("dbo.CatTypes", "CategoryId", "dbo.Categories");
            DropIndex("dbo.TrackSpends", new[] { "UserId" });
            DropIndex("dbo.TrackSpends", new[] { "Type" });
            DropIndex("dbo.TrackSpends", new[] { "SubCategoryType" });
            DropIndex("dbo.TrackSpends", new[] { "CategoryType" });
            DropIndex("dbo.AspNetUserLogins", new[] { "UserId" });
            DropIndex("dbo.AspNetUserClaims", new[] { "UserId" });
            DropIndex("dbo.AspNetUsers", "UserNameIndex");
            DropIndex("dbo.TrackBills", new[] { "UserId" });
            DropIndex("dbo.TrackBills", new[] { "Type" });
            DropIndex("dbo.TrackBills", new[] { "SubCategoryType" });
            DropIndex("dbo.TrackBills", new[] { "CategoryType" });
            DropIndex("dbo.AspNetUserRoles", new[] { "RoleId" });
            DropIndex("dbo.AspNetUserRoles", new[] { "UserId" });
            DropIndex("dbo.AspNetRoles", "RoleNameIndex");
            DropIndex("dbo.CatTypes", new[] { "TypeId" });
            DropIndex("dbo.CatTypes", new[] { "SubCategoryId" });
            DropIndex("dbo.CatTypes", new[] { "CategoryId" });
            DropTable("dbo.TrackSpends");
            DropTable("dbo.AspNetUserLogins");
            DropTable("dbo.AspNetUserClaims");
            DropTable("dbo.AspNetUsers");
            DropTable("dbo.TrackBills");
            DropTable("dbo.AspNetUserRoles");
            DropTable("dbo.AspNetRoles");
            DropTable("dbo.SubCategories");
            DropTable("dbo.InputTypes");
            DropTable("dbo.CatTypes");
            DropTable("dbo.Categories");
        }
    }
}
